package cn.com.scitc.licenseplateback.dao;

import cn.com.scitc.licenseplateback.model.JUserTokensEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface MyJUserTokenDao extends JpaRepository<JUserTokensEntity,Integer> {

    /**
     * 用户记住密码后，再进入进行登录时，会获取到 token ，根据 token 获取信息
     * @param token
     * @return
     */
    @Query(value = "select j from JUserTokensEntity j where j.token = :token")
    JUserTokensEntity findByToken(String token);

    /**
     * 若用户的token 过期，则对数据进行删除
     * @param token
     * @return
     */
    @Modifying
    @Transactional
    @Query(value = "delete from j_user_tokens where token = :token",nativeQuery = true)
    int deleteByToken(String token);

    @Query(value = "select j from JUserTokensEntity j where j.userId = :userid")
    JUserTokensEntity findByUserId(String userid);


}
